package com.xwj.aop;

import java.lang.reflect.Method;

/**
 * 前置通知
 * @author xwj
 * @date 2020/4/11
 */
public class BeforeAdvice implements Advice {
    /**
     * 目标对象
     */
    private Object target;
    /**
     * 切面逻辑
     */
    private MethodInvocation methodInvocation;

    public BeforeAdvice(Object target, MethodInvocation methodInvocation) {
        this.target = target;
        this.methodInvocation = methodInvocation;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        methodInvocation.invoke();
        return method.invoke(target, args);
    }
}
